package teatime.core.bussiness.base;

import java.util.Date;

import teatime.core.model.entity.Account;
import teatime.core.model.entity.Person;
import teatime.core.service.AccountManagerImpl;
import teatime.core.service.manager.AccountManager;

public abstract class BaseRegister {
	
	private AccountManager<Account> accountManager;
	private Account account;
	private String accountName;
	private String accountPassword;

	public void setAccountManager(AccountManager<Account> accountManager) {
		this.accountManager = accountManager;
	}

	public Account getAccount() {
		return account;
	}

	public void setAccount(Account account) {
		this.account = account;
	}

	public String getAccountName() {
		return accountName;
	}

	public void setAccountName(String accountName) {
		this.accountName = accountName;
	}

	public String getAccountPassword() {
		return accountPassword;
	}

	public void setAccountPassword(String accountPassword) {
		this.accountPassword = accountPassword;
	}

	public BaseRegister() {
		initialize();
	}

	public BaseRegister(Account account) {
		setAccount(account);
	}

	public String doRegister() {
		accountManager = new AccountManagerImpl();
		if (accountManager.findUniqueBy(account.PROP_ACCOUNT_NAME,
				account.getAccountName()) == null) {
			account.addToPersons(new Person());
			account.setAccountCreateDate(new Date());
			account.setAccountStatusId("001");
			account.setAccountStatusDetailId("01");
			account.setAccountTypeId("001");
			account.setAccountTypeDetailId("01");
			accountManager.save(getAccount());
			return "success";
		}
		return "error";
	}

	private void initialize() {
		// TODO Auto-generated method stub
	}
}
